<?php

class AuthInstallForm extends CFormModel
{
	public $password;
    protected $_module;
    
	public function rules()
	{
		return array(
			array('password', 'required'),
			array('password', 'CStringValidator', 'min'=>9),
		);
	}
    
    /**
     * @return AuthModule
     * @throws CException 
     */
    public function getModule()
    {
        if(empty($this->_module) || ! ($this->_module instanceof AuthModule))
            throw new CException('the module must be a instance of AuthModule');
        
        return $this->_module;
    }
    
    public function setModule($module)
    {
        if( ! ($module instanceof AuthModule))
            throw new CException('the module must be a instance of AuthModule');
        
        $this->_module = $module;
    }
    
    public function save()
    {
        $superUser = $this->getModule()->getSuperUser(true);
        return $superUser->updatePassword($this->password);
    }
}
